package com.wcgksoft.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * session拦截器
 * @author ThinkGem
 * @version 2014-8-19
 */
public class SessionInterceptor implements HandlerInterceptor {

	protected static Logger logger= LoggerFactory.getLogger(SessionInterceptor.class);
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {
		Object obj = request.getSession().getAttribute("build_session_user");
		if(obj==null||"".equals(obj.toString())){
			response.sendRedirect(request.getSession().getServletContext().getContextPath()+"/login.html");
			return false;
		}
		return true;
	}
 
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
		if (modelAndView != null){
			logger.info("ViewName: " + modelAndView.getViewName());
		}
	}
 
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
                                Object handler, Exception ex) throws Exception {
		// 保存日志
		//LogUtils.saveLog(request, handler, ex, null);
		// 打印JVM信息。
		if (logger.isDebugEnabled()) {
			
		}
		
	}
}
